import { createApp } from 'vue'
import Message from './Message.vue'
import { IMessageParams } from '@/types'
const messageCreate = (
  { type, message, timeout = 2000 }: IMessageParams,
  callback?: () => void
): void => {
  const messageApp = createApp(Message, { type, message })
  const mountNode = document.createElement('div')
  document.body.appendChild(mountNode)
  messageApp.mount(mountNode)
  setTimeout(() => {
    messageApp.unmount()
    document.body.removeChild(mountNode)
    callback && callback()
  }, timeout)
}
export default messageCreate
